<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryParams" :model="queryParams" @submit.native.prevent>
          <el-row>
            <el-col :span="6">
              <el-form-item label="手机号" prop="mobile">
                <el-input
                  v-model="queryParams.mobile"
                  placeholder="请输入手机号"
                  class="w-100"
                  @keyup.enter.native="handleQuerys"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuerys">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>
    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">短信回执</div>
        <div class="op_right">
          <div class="switchbox">
            <span class="switchName">扣卡短信验证开关</span>
            <div class="emptyBox" @click="ChangeSwitch">
              <div class="empty"></div>
              <el-switch
                v-model="SwitchValue"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-value="Y"
                inactive-value="N"
              >
              </el-switch>
            </div>
          </div>
        </div>
      </div>

      <div class="table_list">
        <el-table :data="tableData" stripe style="width: 100%">
          <el-table-column prop="mobile" label="手机号码"></el-table-column>
          <el-table-column prop="storeName" label="门店名称"></el-table-column>
          <el-table-column
            prop="reportStatus"
            label="实际收到短信状态"
          ></el-table-column>
          <el-table-column prop="errmsg" label="用户接收短信状态" width="300px">
            <!-- <template slot-scope="scope">
              <span>{{ MoneyUpType[scope.row.salaryUpType] }}</span>
            </template> -->
          </el-table-column>
          <el-table-column
            prop="description"
            label="状态描述"
            width="300px"
          ></el-table-column>
          <el-table-column
            prop="userReceiveTime"
            label="短信接受时间"
          ></el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { getSmsReceiptsPage, checkOpenQuery, EditsmsOpen } from "@/api/bpm/sms";
export default {
  name: "EryuoaStoreAddrules",

  data() {
    return {
      loading: false,
      activeIndex: 1,
      currentIndex: 1,
      tableData: [],
      StoreSlist: [],
      title: "",
      value: "",
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        mobile: "",
      },

      total: 0,

      SwitchValue: "",
    };
  },

  created() {
    this.getList();
    this.checkOpenQueryData();
  },

  mounted() {},

  methods: {
    ChangeSwitch() {
      let status = this.SwitchValue === "Y" ? "关闭" : "开启";
      this.$confirm(
        "确认要" + status + "扣卡短信验证开关吗, 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          EditsmsOpen({
            openStatus: this.SwitchValue === "Y" ? "N" : "Y",
          })
            .then((Res) => {
              // console.log("修改按钮开关状态", Res);
              this.checkOpenQueryData();
            })
            .catch((err) => {});
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        })
        .catch(() => {});
    },
    // 查询扣卡短信验证开关
    checkOpenQueryData() {
      this.loading = true;
      checkOpenQuery({})
        .then((res) => {
          console.log(res, "RES");
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.SwitchValue = data;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    resQ() {
      this.queryParams.pageNo = 1;
      this.total = 0;
      this.tableData = [];
      this.getList();
    },
    handleQuerys() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    // 表单重置
    resetFormData(formName) {
      // console.log(this.$refs[formName]);
      this.$refs[formName].resetFields();
    },

    // 短信回执
    getList() {
      this.loading = true;
      getSmsReceiptsPage(this.queryParams)
        .then((res) => {
          console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.tableData = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryParams");
      this.handleQuery();
    },

    // 表单重置
    resetFormData(formName) {
      console.log(this.$refs[formName]);
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.separate_left {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-right: 12px;
}
.separate_right {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-left: 12px;
}

.check {
  font-size: 12px;
  color: #0052d9;
}

.list_Stores {
  height: 22px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.9);
  line-height: 22px;
  .list_Stores_item {
    height: 46px;
    line-height: 46px;
    background: #ffffff;
    padding-left: 47px;
    border-bottom: 1px solid #e7e7e7;
  }
}

.AddRules_box {
  padding: 0 24px;
  .Rules_form_box {
    display: flex;
    .Rules_form_select {
      margin-right: 10px;
    }
  }
}

.radio_box {
  display: flex;
  margin-bottom: 10px;
}

.up_ipt {
  width: 300px;
  margin-right: 20px;
}
.down_ipt {
  width: 300px;
  margin-left: 10px;
}
.percentIcon {
  position: absolute;
  top: 55px;
  right: -15px;
}
.switchbox {
  display: flex;
  align-items: center;
  .switchName {
    display: block;
    margin-right: 5px;
  }
  .emptyBox {
    position: relative;
    .empty {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      z-index: 99;
    }
  }
}
</style>
